package com.blb.ssh.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.blb.ssh.dao.UserDao;
import com.blb.ssh.entity.PageHelp;
import com.blb.ssh.entity.User;
import com.blb.ssh.exception.BusinessException;
import com.blb.ssh.service.UserService;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {
	
	@Autowired
	private UserDao userDao;
	
	public void login(String username, String password) throws BusinessException {
		User user = userDao.getUserByUserName(username);
		if (user==null) {
			throw new BusinessException("用户名不存在");
		}
		if (!user.getPassword().equals(password)) {
			throw new BusinessException("密码错误");
		}
	}

	@Override
	public PageHelp getUserList(int pageNo, int pageSize) {
		List<User> list = userDao.getList(pageNo, pageSize);
		int count = userDao.getCount(pageNo, pageSize);
		PageHelp pageHelp = new PageHelp(count, list);
		return pageHelp;
	}
	
}
